<?php
/**
 * Created by PhpStorm.
 * User: mr.hao
 * Date: 2018/8/15
 * Time: 15:32
 */

namespace App\Atransform;


use League\Fractal\TransformerAbstract;
use Modules\Shop\Entities\Article;

class ArticleTransform extends TransformerAbstract
{

//    这里注意模型关联的方法，三个地方要写成一致的
    protected $availableIncludes = ['moxin'];


//    调用laravel自己给我们提供的接口
    public function transform(Article $article)
    {
        return [
          'id'=>$article['id'],
            'title'=>$article['title'],
            'content'=>$article['content'],
            'thumb'=>$article['thumb']
        ];
    }

//    获得文章分类的数据，使用include往文章数据里插入分类数据
    public function includeMoxin(Article $article)
    {
        return $this->item($article->moxin,new CategoryTransform());
    }

}